package com.lefevre.cms.bean.message;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * 私信
 *
 * @author Lefevre
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("private_message")
@Entity
@Table(name = "private_message", indexes = {
        @Index(name = "private_message_1_idx", columnList = "userId,status,sendTimeFormat"),
        @Index(name = "private_message_2_idx", columnList = "userId,friendUserId,status,sendTimeFormat")})
public class PrivateMessage implements Serializable {
    private static final long serialVersionUID = -3323100153035020584L;

    /**
     * Id  Id的后4位为用户Id的后4位
     **/
    @Id
    @Column(length = 50)
    @TableId(type = IdType.INPUT)
    protected String id;

    /**
     * 私信用户Id(虚拟字段)   userId和friendUserId字段值对调
     **/
    @TableField("userId")
    protected Long userId;

    /**
     * 私信对方用户Id (虚拟字段)
     **/
    @TableField("friendUserId")
    protected Long friendUserId;

    /**
     * 私信对方用户名称
     **/
    @Transient
    @TableField(exist = false)
    protected String friendUserName;

    /**
     * 私信对方呢称
     **/
    @Transient
    @TableField(exist = false)
    protected String friendNickname;

    /**
     * 私信对方头像路径
     **/
    @Transient
    @TableField(exist = false)
    protected String friendAvatarPath;

    /**
     * 私信对方头像名称
     **/
    @Transient
    @TableField(exist = false)
    protected String friendAvatarName;

    /**
     * 发送者用户Id
     **/
    @TableField("senderUserId")
    protected Long senderUserId;

    /**
     * 接受者用户Id
     **/
    @TableField("receiverUserId")
    protected Long receiverUserId;

    /**
     * 发送者用户名称
     **/
    @Transient
    @TableField(exist = false)
    protected String senderUserName;

    /**
     * 发送者呢称
     **/
    @Transient
    @TableField(exist = false)
    protected String senderNickname;

    /**
     * 发送者头像路径
     **/
    @Transient
    @TableField(exist = false)
    protected String senderAvatarPath;

    /**
     * 发送者头像名称
     **/
    @Transient
    @TableField(exist = false)
    protected String senderAvatarName;

    /**
     * 消息内容
     **/
    @Lob
    @TableField("messageContent")
    protected String messageContent;

    /**
     * 消息状态 10:未读  20:已读  110:未读删除  120:已读删除
     **/
    @TableField("status")
    protected Integer status = 10;

    /**
     * 发送时间格式化
     **/
    @TableField("sendTimeFormat")
    protected Long sendTimeFormat;

    /**
     * 阅读时间格式化
     **/
    @TableField("readTimeFormat")
    protected Long readTimeFormat;

    /**
     * 发送时间
     **/
    @Transient
    @TableField(exist = false)
    protected Date sendTime;

    /**
     * 阅读时间
     **/
    @Transient
    @TableField(exist = false)
    protected Date readTime;
}
